# -*- coding:utf8-*-
import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options as chrome_options
from selenium.webdriver.firefox.options import Options as firefox_options


def main1():
    b = webdriver.Chrome()
    b.get('http://www.baidu.com')
    time.sleep(5)
    b.quit()


# chrome 无界面游览器插件
#  https://www.bbsmax.com/A/x9J2vPVjJ6/ 配置说明
def main2():
    chrome_option = chrome_options()
    chrome_option.add_argument('--headless')
    chrome_option.add_argument('--disable-gpu')
    driver = webdriver.Chrome(chrome_options=chrome_option)
    driver.get("http://www.baidu.com")
    print(driver.page_source)
    driver.close()


# firefox 无界面游览器插件
def main3():
    firefox_option = firefox_options()
    firefox_option.add_argument('-headless')
    driver = webdriver.Firefox(firefox_options=firefox_option)
    # driver = webdriver.Firefox()
    driver.get("https://www.baidu.com/")
    print(driver.page_source)
    driver.close()


if __name__ == '__main__':
    # main1()
    main2()
    # main3()
